﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="newslist.aspx.cs" Inherits="UI.system.page.news.newslist" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="Model" %>
<%@ Import Namespace="DAL" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="/system/js/jquery.min.js"></script>
    <script src="/system/layui/layui.js"></script>
    <script src="/system/layui/lay/modules/laydate.js"></script>
    <script src="/system/js/common.js"></script>
    <script src="/system/js/md5.js"></script>
    <script src="../../js/swfupload.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/system/layui/css/layui.css">
    <link rel="stylesheet" href="/system/css/iframe.css">
    <script src="/js/clipboard.min.js"></script>
    <style>
        td img
        {
            height: 40px;
            float: left;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="layer-toolbar layui-form">
        <div class="layer-toolbar-left">
            <div style="position: absolute; left: -1000px; top: -1000px;">
                <input type="radio" name="radio" value="" title="" />
            </div>
        </div>
        <div class="layer-toolbar-right">
            <input id="keyword" type="text" name="title" placeholder="作者" autocomplete="off"
                class="layui-input" value="" style="width: 150px;" onkeyup='CRM.Enter("#search")'>
            <a id="search" class="layui-btn layui-btn-small layui-btn-normal" onclick="Search()">
                搜索</a> <a class="layui-btn layui-btn-small" onclick="Search()">刷新</a>
        </div>
    </div>
    <div id="iframe" class="layer-iframe">
        <div class="layui-form">
            <table class="layui-table">
                <colgroup>
                    <col width="180">
                    <col width="200">
                    <col width="80">
                    <col width="30">
                    <col width="30">
                    <col width="120">
                    <col width="88">
                    <col width="30">
                    <col width="50">
                    <col width="80">
                    <col width="100">
                </colgroup>
                <thead>
                    <tr>
                        <th>
                            标题
                        </th>
                        <th>
                            内容
                        </th>
                        <th>
                            作者
                        </th>
                        <th>
                            点赞量
                        </th>
                        <th>
                            浏览量
                        </th>
                        <th>
                            省市区
                        </th>
                        <th>
                            封面图片
                        </th>
                        <th>
                            联系人
                        </th>
                        <th>
                            联系人电话
                        </th>
                        <th>
                            单位名称
                        </th>
                        <th>
                            操作
                        </th>
                    </tr>
                </thead>
                <tbody id="layer-table">
                    <tr>
                        <td colspan="20" class="center">
                            数据加载中...
                        </td>
                    </tr>
                </tbody>
                <script id="data-table" type="text/html">
     {{#  layui.each(d, function(index, item){ }}
      <tr>
        <td><a onclick="Show_Messages({{item.ID}})">{{item.Title}}</td>
        <td>{{item.Fcontents}}</td>
        <td>{{item.Name}}</td>
        <td>{{item.Praise}}</td>
        <td>{{item.Pageviews}}</td>
        <td>{{item.Province}}-{{item.City}}-{{item.Area}}</td>
        <td><img src={{item.CoverImg}}  width="50px" /></td>
        <td>{{item.Contact}}</td>
        <td>{{item.Phone}}</td>
        <td>{{item.Company}}</td>
        <td style="line-height:30px;">
        <a class="layui-btn layui-btn-mini" onclick="Save_News({{item.ID}})" style="margin-bottom:3px;">编辑</a>
        <a class="layui-btn layui-btn-mini" onclick="Save_Messages({{item.ID}})" style="margin-bottom:3px;">留言</a>
        <a class="layui-btn layui-btn-mini layui-btn-danger" onclick="Delete_News(this,{{item.ID}})">删除</a>
        </td>
      </tr>
      {{#  }); }}
                </script>
            </table>
        </div>
    </div>
    <div id="layer-page" class="layer-page">
    </div>
    </form>
    <script>
        layui.use(['form', 'laytpl', 'element'], function () {
            $ = layui.jquery, form = layui.form(), laytpl = layui.laytpl;
            Init_Pager(1);
            form.on("select(state)", function (data) {
                Search();
            });
            form.on("select(type)", function (data) {
                Search();
            });
        });

        function Init_Pager(pageindex) {
            var data = {};
            data.act = "Find_News";
            data.startindex = pageindex;
            data.keyword = $("#keyword").val();
            data.state = $("#state").val();
            data.type = $("#type").val();
            data.sign = GetSign(data.act);
            Loading();
            Ajax.Post("/tools/Admin.ashx", data, function (r) {
                var json = $.parseJSON(r);
                if (json.state) {
                    Pager(json.data.list, json.data.count);
                }
                else {
                    LayerBox.Error(json.msg);
                }
            });
        };

        function Delete_News(o, id) {
            LayerBox.Confirm("您确定要删除吗？", function () {
                Delete_Table(o, id, "Delete_News");
            });
        };

        function Save_News(id) {
            LayerBox.Loading();
            Ajax.Get("/system/page/news/newsadd.aspx?id=" + id, function (html) {
                LayerBox.Close.ByAll();
                var title = id == 0 ? "新增" : "修改";
                window.parent.LayerBox.Show(title + "活动", html, 605, 710, null, function (form) {
                    var data = form;
                    data.act = "Save_News";
                    data.id = id;
                    data.content = ue.getContent();
                    data.sign = GetSign(data.act);
                    data.coverimg = window.parent.$(".img_container img").attr("src");
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                LayerBox.Close.ByAll();
                                if (id == 0) {
                                    $(".layui-laypage").remove();
                                    Init_Pager(1);
                                } else {
                                    var currpage = 1;
                                    if ($(".layui-laypage-curr em").length > 0) {
                                        currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                    }
                                    Init_Pager(currpage);
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
                window.parent.UE.delEditor('context');
                var ue = window.parent.UE.getEditor('context');
                var upload = new window.parent.Upload_File("upload_img");
                upload.swfu.handle = "upload_active";
            });
        };

        function Save_Messages(id) {
            LayerBox.Loading();
            Ajax.Get("/system/page/news/messagesadd.aspx?id=" + id, function (html) {
                LayerBox.Close.ByAll();
                var title = id == 0 ? "新增" : "修改";
                window.parent.LayerBox.Show(title + "留言", html, 605, 710, null, function (form) {
                    var data = form;
                    data.act = "Save_Message";
                    data.articleid = id;
                    data.sign = GetSign(data.act);
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                LayerBox.Close.ByAll();
                                if (id == 0) {
                                    $(".layui-laypage").remove();
                                    Init_Pager(1);
                                } else {
                                    var currpage = 1;
                                    if ($(".layui-laypage-curr em").length > 0) {
                                        currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                    }
                                    Init_Pager(currpage);
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
                window.parent.UE.delEditor('context');
                var ue = window.parent.UE.getEditor('context');
                var upload = new window.parent.Upload_File("upload_img");
                upload.swfu.handle = "upload_active";
            });
        };

        function Show_Messages(id) {
            LayerBox.Loading(); 
            Ajax.Get("/system/page/news/messageslist.aspx?id=" + id, function (html) {
                LayerBox.Close.ByAll();
                window.parent.LayerBox.Detail("文章留言", html, 605, 710, null, function (form) {
                    var data = form;
                    data.act = "Find_AllMessage";
                    data.articleid = id;
                    data.sign = GetSign(data.act);
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                LayerBox.Close.ByAll();
                                if (id == 0) {
                                    $(".layui-laypage").remove();
                                    Init_Pager(1);
                                } else {
                                    var currpage = 1;
                                    if ($(".layui-laypage-curr em").length > 0) {
                                        currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                    }
                                    Init_Pager(currpage);
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
            });
        };
    </script>
</body>
</html>
